﻿#include "pch.h"
#include "opencv2/opencv.hpp"

using namespace cv;
using namespace std;

/*
第一周进阶作业第二题代码
*/
int helloWorld(void)
{
	const char* fn = "D:\\Program Files\\opencv\\sources\\samples\\data\\lena.jpg";
	Mat image = imread(fn);
	imshow("Hello,world!", image);
	waitKey(0);
	return 0;
}

/*
第一周进阶作业第三题代码(RGB)
*/
int colorModelRGB(void) 
{
	const char* fn = "D:\\Program Files\\opencv\\sources\\samples\\data\\lena.jpg";
	Mat image1 = imread(fn);

	Mat image, gray, hsv, hsvChannels[3];
	pyrDown(image1, image);

	vector<Mat>m;
	split(image, m); //提取通道信息，但是当未把其他通道设置为0时显示为灰度图，但各通道信息不同
	vector<Mat>Rchannels, Gchannels, Bchannels;
	//提取通道信息，把orig的通道数据复制到channals
	split(image, Rchannels);
	split(image, Gchannels);
	split(image, Bchannels);
	//将其他通道信息设置为0
	Rchannels[1] = 0;
	Rchannels[2] = 0;
	Gchannels[0] = 0;
	Gchannels[2] = 0;
	Bchannels[0] = 0;
	Bchannels[1] = 0;
	//合并通道信息
	merge(Rchannels, m[0]);
	merge(Gchannels, m[1]);
	merge(Bchannels, m[2]);
	//显示各通道信息
	imshow("B", m[0]);
	imshow("G", m[1]);
	imshow("R", m[2]);
	waitKey(0);
	return 0;

}

/*
第一周进阶作业第三题代码(HSV)
*/
int colorModelHSV(void)
{
	const char* fn = "D:\\Program Files\\opencv\\sources\\samples\\data\\lena.jpg";
	Mat image1 = imread(fn);

	Mat image, gray, hsv, hsvChannels[3];
	pyrDown(image1, image);

	cvtColor(image, hsv, COLOR_BGR2HSV);
	split(hsv,hsvChannels);
	imshow("Hue", hsvChannels[0]);
	imshow("Saturation", hsvChannels[1]);
	imshow("Value", hsvChannels[2]);
	waitKey(0);
	return 0;

}

int main(void)
{
	//helloWorld();
	//colorModelRGB();
	colorModelHSV();
}